/**
 * struct ListNode {
 *  int val;
 *  struct ListNode *next;
 * };
 */
class Solution {
public:
    /**
     *
     * @param head ListNode类
     * @param m int整型
     * @param n int整型
     * @return ListNode类
     */
    ListNode* reverseBetween(ListNode* head, int m, int n)
    {
        //write code here
        if(m==n)//特殊情况
          return head;
        
        vector<int>save;
         
        ListNode*tail=head;
        //确定区间
      int count=1;
        while(count<m)
        {
            count++;
            tail=tail->next;
        }
        save.push_back(tail->val);
        ListNode* begin=tail;
        while(count<n)
        {
            count++;
            tail=tail->next;
            save.push_back(tail->val);
        }
         
        count=(n-m)+1;
        while(count--)
        {
            begin->val=save.back();
            begin=begin->next;
            save.pop_back();
        }
        return head;
    }
};
